package com.example.teamtribe.database;

import android.support.annotation.NonNull;

import org.litepal.crud.DataSupport;

import java.sql.Date;

public class Chatting extends DataSupport implements Comparable<Chatting> {

    private int realId;
    private int userId;
    private Date date;
    private String contend;

    public Chatting(int realId, int userId, Date date, String contend) {
        this.realId = realId;
        this.userId = userId;
        this.date = date;
        this.contend = contend;
    }

    public Chatting(int realId, int userId, String contend) {
        this.realId = realId;
        this.userId = userId;
        this.date = new Date(System.currentTimeMillis());
        this.contend = contend;
    }

    public synchronized boolean saveOrUpdate() {
        return saveOrUpdate("realId = ?", realId + "");
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (obj instanceof Chatting) {
            Chatting chatting = (Chatting) obj;
            return realId == chatting.realId;
        }
        return false;
    }

    @Override
    public int compareTo(@NonNull Chatting o) {
        return date.compareTo(o.date);
    }

    public int getRealId() {
        return realId;
    }

    public int getUserId() {
        return userId;
    }

    public Date getDate() {
        return date;
    }

    public String getContend() {
        return contend;
    }
}
